home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 352_01 / lcdemo.cpp < prev    next >
C/C++ Source or Header  |  1991-02-28  |  2KB  |  94 lines

  1. // testcl.cpp
  2. //         this C++ routine tests and demonstrates the features of class LinkClass
  3. //
  4. #include <stdlib.h>
  5. #include <iostream.h>
  6.  
  7. #include "wtwgpp.h"
  8.  
  9. class odd_num
  10.     {
  11.     InheritLinkClass(odd_num)
  12.     public: 
  13.         int t;
  14.         odd_num (int i=0): node(base, this) {t=i;};
  15.         ~odd_num() { node.unLink(); };
  16.         friend ostream& operator<<(ostream& ost, odd_num &t_obj) 
  17.                 { return ost<<t_obj.t; };
  18.     };
  19.     
  20. class even_num
  21.     {
  22.     InheritLinkClass(even_num)
  23.     public: 
  24.         int t;
  25.         even_num (int i=0): node(base,this) { t=i; };
  26.         ~even_num()         { node.unLink(); };
  27.         friend ostream& operator<<(ostream& ost, even_num &t_obj) 
  28.                 { return ost<<t_obj.t; };
  29.     };
  30.     
  31. main (int argc, char **argv)
  32.     {
  33.     for ( int i =0; i<argc; ++i )
  34.             {
  35.             cout <<  argv[i] << ' ';
  36.             }
  37.  
  38.     odd_num  x1(1), x3(3), x5(5),  *xp1, *d7;
  39.  
  40.     cout << "\nClass odd_num  isEmpty=="<< odd_num::isEmpty() 
  41.          << "\nClass even_num isEmpty=="<< even_num::isEmpty()
  42.          << '\n';
  43.  
  44.     even_num  x2(2), x4(4), x6(6),  *xp2, *d8;
  45.  
  46.  
  47.     d7 = new odd_num(7);
  48.     d8 = new even_num(8);
  49.     
  50.  
  51.  
  52.     odd_num  x9(9);
  53.     even_num  x10(10); 
  54.  
  55.     cout << '\n';
  56.  
  57.     for ( xp1= x1.first(); xp1; xp1=xp1->next() )
  58.         {    
  59.         cout<<  "  xp1 = " << *xp1 ;
  60.         }    
  61.     cout << '\n';
  62.     
  63.     for ( xp2= x2.first(); xp2; xp2=xp2->next() )
  64.         {    
  65.         cout<<  "\nxp2 = " << *xp2 ;
  66.         }
  67.  
  68.     //  cout << "\n Now removing elements 7 and 8 from lists";
  69.     puts (  "\n Now remove 7 and 8, swap 1,3 and 2,4" );
  70.     x3.moveBelow(x1);
  71.     x2.moveAbove(x4);
  72.  
  73.     delete d7;
  74.     delete d8;
  75.     
  76.     cout << '\n';
  77.  
  78.     for ( xp1= x1.first(); xp1; xp1=xp1->next() )
  79.         {    
  80.         cout<<"   xp1 = " << *xp1 ;
  81.         }    
  82.         
  83.     cout << '\n';
  84.     
  85.     for ( xp2= x2.first(); xp2; xp2=xp2->next() )
  86.         {    
  87.         cout<<  "   xp2 = " << *xp2 ;
  88.         }    
  89.     cout<< "\nThats all folks\n";
  90.  
  91.     return 0;    // end main()
  92.     }    
  93.     
  94.